
const schedulesDao = require('../../models/schedulesModel.js');


module.exports = {
    //显示所有信息
    async showAll(){
        return await schedulesDao.find().exec()
    },
    //增加数据
    async insertSchedules(movieId,cinemasId,theaterId,showTime,price){
        return await schedulesDao.create({
            movieId,
            cinemasId,
            theaterId,
            showTime,
            price
        })
    },
    //删除数据
    async deleteSchedules(SchedulesId){
        return await schedulesDao.deleteOne({"_id":SchedulesId}).exec()
    },
    //查询信息
    async showSchedules(_id){
        return await schedulesDao.find(_id).exec()
    },
    //修改信息
    async updateSchedules({_id,movieId,cinemasId,theaterId,showTime,price}){
        return await schedulesDao.updateOne({_id},{movieId,cinemasId,theaterId,showTime,price}).exec()
    },
    //分页
    // currentPage:当页页数
    // pageSize： 每页显示的条数 
    async accessToPag({
        currentpage,
        pagesize
    }) {
        return await schedulesDao.find()
            .skip((currentpage - 1) * pagesize)
            .limit(pagesize)
            .sort({
                '_id': -1
            })
            .exec()
    },
    //数据的总条数
    async getsNumber() {
        return schedulesDao.countDocuments().exec()
    },

    
}